package com.geline.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.geline.demo.dto.TownHouseListQry;
import com.geline.demo.service.ExcelFileService;
import com.geline.demo.web.AbstractExcelController;
import com.geline.extension.domain.PageQuery;
import com.geline.extension.domain.TableDataInfo;
import com.geline.extension.util.QueryWrapperUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: mx
 * @date: 2024-07-25 15:13
 */
@Tag(name = "ExcelFile", description = "文件管理")
@RestController
@RequestMapping("/excelFile")
@Slf4j
public class ExcelFileController extends AbstractExcelController {

    @Autowired
    private ExcelFileService excelFileService;

    /**
     * localhost:9001/excelFile/pageAll?pageNum=1&pageSize=10
     * @param pageQuery
     * @param query
     * @return
     */
    @Operation(description = "分页查询")
    @GetMapping("/pageAll")
    public TableDataInfo pageAll(PageQuery pageQuery, TownHouseListQry query) {
        QueryWrapper wrapper = QueryWrapperUtil.build(query);
        Page page = this.excelFileService.page(pageQuery.build(), wrapper);
        return TableDataInfo.build(page);
    }

    /**
     * 支持生成下拉框（单选下拉，多选下拉，级联下拉）
     * localhost:9001/excelFile/exportAll?pageNum=1&pageSize=10
     * @param pageQuery
     * @param query
     */
    @Operation(description = "导出Excel")
    @GetMapping("/exportAll")
    public void exportAll(PageQuery pageQuery, TownHouseListQry query) {
        TableDataInfo tableDataInfo = pageAll(pageQuery, query);
        super.exportExcel("townHouse", tableDataInfo, "文件名");
    }
}
